package com.atjava.nebula.core.exception.handler.impl;

import com.atjava.nebula.core.exception.bean.ExceptionInfo;
import com.atjava.nebula.core.exception.handler.IExceptionHandler;
import com.atjava.nebula.core.exception.support.ExceptionUtil;

/**
 * 异常可能没有在expinfo.xml文件中定义,对于这种情况
 * */
public class FileLogExceptionHandler implements IExceptionHandler {
	
	public FileLogExceptionHandler() {
	}
	
	public void handleException(Throwable exp) {
		
		//得到一个ExceptionInfo对象
		//如果此Exception没有在expinfo.xml中定义,则返回null
		ExceptionInfo expInfo = ExceptionUtil.getExceptionInfo(exp);
		//根据ExceptionInfo对象进行记录异常信息
		
		Class clazz=null;
		try {
			clazz=Class.forName(exp.getStackTrace()[0].getClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		if(expInfo != null) {
			ExceptionUtil.logException(clazz, exp, expInfo.getLoggingType());
		} else {
			ExceptionUtil.logException(clazz, exp, ExceptionUtil.LOGTYPE_ERROR);
		}
		return ;
	}

}